<template>
  <div class="home">
    <div class="header">
      <van-tabs v-model="active" 
        background="#111214" 
        title-inactive-color="#fff" 
        title-active-color="#fff"
        color="transparent">
          <van-tab v-for="index in topBars" :key="index.id">
            <template #title> 
              <div><van-icon :name="index.logo" size="24px"/></div>
              {{index.text}}     
            </template>
          </van-tab>
      </van-tabs>
    </div>
    <!-- 精选栏目 -->
    <div class="selectMenu">
      <div class="mediaColumns">
        <div class="head">
          <div class="title">精选栏目</div>
          <div class="more">更多<van-icon name="arrow" /></div>
        </div>
        <van-tabs v-model="active" color="transparent" title-inactive-color="#333">
          <van-tab v-for="(item,index) in special" :key="item.post_id" >
            <template #title> 
              <div class="avatar-wrap" @click="jumpColumn(index)">
                <div class="avatar">
                  <img :src="item.post_avatar">
                </div>
                <p class="tit">{{item.title}}</p>
                <p class="upDateTime">{{item.material_last_time}}</p>
              </div>
            </template>
          </van-tab>
        </van-tabs>
      </div>
      <!-- 为你推荐 -->
      <div class="recommendFor">
        <div class="fortit">为你推荐</div>
        <ul>
          <li v-for="(item,index) in feeds" :key="index">
            <div class="feed-tit">{{item.title}}</div>
            <div class="feedImg">
              <div v-for="(value,el) in item.thumbnail" :key="el"><img :src="value.url?value.url:value.pic_url"></div>
            </div>
            <div class="authorName"><span>{{item.authorName}}</span><span v-if="item.commentCount">{{item.commentCount}}条评论</span></div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'home',
  data() {
    return {
      active: 0,
      topBars:[],//标题
      special:[],//精选栏目
      feeds:[],//为你推荐
    }
  },
  async created(){
    await axios.get('http://localhost:9527/indexdata.json').then(res=>{
      this.topBars = res.data.data.topBars[0]
      this.special = res.data.data.special
      this.feeds = res.data.data.feeds
      console.log(this.feeds);
    })
  },
  methods:{
    jumpColumn(index){
      if(index===0){
        this.$router.push('/columninfo')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.home {
  padding-top: 46px;
  padding-bottom: 55px;
    .van-tab div {
      text-align: center;
    }
    .selectMenu {
      width: 100%;
      background: #fff;
      border-top-right-radius: 20px;
      border-top-left-radius: 20px;
      margin-top: -15px;
      position: relative;
      padding: 15px;
      box-sizing: border-box;
      .mediaColumns {
        .head {
          display: flex;
          justify-content: space-between;
          .title {
            position: relative;
            line-height: 30px;
            font-size: 20px;
            color: #242a33;
          }
          .title::after {
            content: '';
            display: block;
            width: 8px;
            height: 8px;
            position: absolute;
            top: 0;
            right: -10px;
            background: url('../../assets/bk.png') no-repeat;
            background-size: 100%;
          }
          .more {
            font-size: 14px;
            color: #4f535e;
            line-height: 30px;
          }
        }
        .van-tabs {
          margin-top: 10px;
          .avatar-wrap {
            width: 82px;
              .avatar {
              width: 82px;
              height: 82px;
              border-radius: 5px;
              position: relative;
              img {
                width: 100%;
                height: 100%;
                border-radius: 5px;
              }
            }
            .avatar::after {
              content: "";
              position: absolute;
              top: 8px;
              right: -3px;
              display: block;
              width: 3px;
              height:70px;
              border-top-right-radius: 3px;
              border-bottom-right-radius: 3px;
              background: #ebebeb;
            }
            .tit {
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
              font-size: 16px;
              text-align: left;
              margin:8px 0 3px 0;
              // margin: 0;
            }
            .upDateTime {
              font-size: 12px;
              text-align: left;
              margin: 0;
              color: #999;
            }
          }
          
        }
      }
      .recommendFor {
        .fortit {
            position: relative;
            line-height: 30px;
            font-size: 20px;
            color: #242a33;
            margin-top: 20px;
        }
        .fortit::after {
            content: '';
            display: block;
            width: 8px;
            height: 8px;
            position: absolute;
            top: 0;
            left: 82px;
            background: url('../../assets/bk.png') no-repeat;
            background-size: 100%;
          }
          li {
            margin-top: 20px;
           
            border-bottom: 1px solid #F8F8F8;
            .feed-tit {
              font-size: 18px;
              line-height: 26px;
              color: #000;
              overflow: hidden;
              margin-bottom: 5px;
              white-space: normal;
              text-overflow: ellipsis;
              line-clamp: 2;
            }
            .feedImg::after {
              content: '';
              width: 235px;
            }
            .feedImg {
              display: flex;
              flex-wrap: wrap;
              justify-content: space-around;
              div {
                width: 110px;
                height: 75px;
                //  margin-right: 5px;
                img {
                  width: 100%;
                  height: 100%;
                }
              }
            }
            .authorName {
              text-align: left;
              font-size: 12px;
              color: #99A6C4;
              margin: 5px 0 15px 0;
              span {
                margin: 0 5px;
              }
            }
          }
      }
    }
}
.home ::v-deep .header .van-tabs--line .van-tabs__wrap {
    height: 100px;
}
.home ::v-deep .mediaColumns .van-tabs--line .van-tabs__wrap {
    height: 140px;
}
.home ::v-deep .selectMenu {
  .van-tabs__nav--line.van-tabs__nav--complete {
        padding: 0;
    }
    .van-tabs__wrap--scrollable .van-tab {
        padding: 8px;
    }
}
</style>
